﻿/*
*应急物资管理子系统
*案例库
*/
IF EXISTS(SELECT NAME FROM SYSOBJECTS WHERE NAME='Proc_GetCaseLibrarys' AND TYPE='P')
BEGIN
  DROP PROCEDURE Proc_GetCaseLibrarys
END
GO
CREATE PROCEDURE Proc_GetCaseLibrarys
	@pageIndex int,
	@pageSize int,
	@caseName varchar(50),
	@caseType varchar(50)
 AS
DECLARE @SQL nvarchar(1000)
DECLARE @RecordCount int,@P1 INT
DECLARE @Where VARCHAR(200)
IF @PageIndex >1 SET @PageIndex = (@PageIndex-1)*@PageSize +1
SET @Where = ''
IF ((@caseName IS NOT NULL) AND (RTRIM(LTRIM(@caseName))<>''))
BEGIN
  SET @Where = @Where +  ' AND CaseName LIKE ''%'+ @caseName + '%'''
END
IF (@caseType IS NOT NULL )  AND (RTRIM(LTRIM(@caseType))<>'')
BEGIN
	SET @Where = @Where +  ' AND CaseType = '''+ @caseType + ''''
END
IF ((LEN(@Where)>0) AND (LEFT(@Where,5)=' AND')) 
BEGIN
	SET @Where = Right(@Where,LEN(@Where)-5)
END
SET @SQL = N'SELECT * FROM  Eaer_CaseLibrary ORDER BY OccurrenceTime DESC'
IF (LEN(@Where)>0)
BEGIN
  SET @SQL = 'SELECT * FROM  Eaer_CaseLibrary WHERE ' + @Where + ' ORDER BY OccurrenceTime DESC'
END
EXEC sp_cursoropen @P1 OUTPUT, @SQL, @scrollopt = 1, @ccopt = 335873, @rowcount = @RecordCount OUTPUT 
IF (@P1 != 0)
BEGIN
  EXEC sp_cursorfetch @P1, 32, @PageIndex, @PageSize 
  EXEC sp_cursorclose @P1
END
select @RecordCount
return @@ERROR 